package com.zbkj.crmeb.merchant.api.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.taobao.pac.sdk.cp.dataobject.request.MODUAN_ORDER_CREATE.request;
import com.zbkj.crmeb.store.dao.StoreProductMerDao;


/**
 * 交易模块
 *
 * @author 遇见
 */
@RestController
@RequestMapping("/trade")
@Api(value = "交易模块", tags = {"交易模块"})
@Slf4j
public class TradeRestApi {

    @RequestMapping(value = "/lantuWxPay/callback")
    public String lantuWechatPayCallback(@RequestParam Map<String, String> data, HttpServletRequest request, HttpServletResponse response) {
        log.info("[] 支付回调,data:{}",JSONObject.toJSONString(data));
//        HttpServletRequest request = RequestHolder.getRequest();
        String sign2 = request.getParameter("sign");
        System.out.println("sign2:"+sign2);
        log.info("接收到回调通知,sign:{}",sign2);
        Map<String, String[]> parameterMap = request.getParameterMap();
        String jsonStr2 = JSONObject.toJSONString(parameterMap);
        System.out.println("jsonStr2:"+jsonStr2);
        log.info("接收回调通知 request jsonStr2:{}",jsonStr2);
        JSONObject obj = JSONObject.parseObject(jsonStr2);
        System.out.println("obj:"+obj.toJSONString());
        log.info("接收到回调通知 request obj :{}",obj.toJSONString());
        String orderNo2 = request.getParameter("outTradeNo");
        System.out.println("orderNo2:"+orderNo2);

        try {
            String orderNo = request.getParameter("outTradeNo");
            if (StringUtils.isNotEmpty(orderNo)) {

                return "SUCCESS";
            }
        } catch (Exception e) {
            log.error("[callback] 蓝兔支付第三方微信支付回调异常");
            e.printStackTrace();
        }
        return "FAIL";
    }

}
